package com.faklyn.bootjwt.skiplist;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.beans.PropertyVetoException;
import java.util.Comparator;
import java.util.NavigableSet;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListSet;

@Slf4j
public class TestSkipList {

    public static void main(String[] args) {
        ConcurrentSkipListSet concurrentSkipListSet = new ConcurrentSkipListSet();
        concurrentSkipListSet.add(1);
        concurrentSkipListSet.add(5);
        concurrentSkipListSet.add(2);
        concurrentSkipListSet.add(10);
        concurrentSkipListSet.add(7);
        concurrentSkipListSet.add(3);
        log.info("concurrentSkipListSet={}",concurrentSkipListSet);
        NavigableSet navigableSet = concurrentSkipListSet.headSet(5);
        log.info("navigableSet={}",navigableSet);

        ConcurrentSkipListSet scoreSkipListSet = new ConcurrentSkipListSet(Score.ScoreComparator);
        scoreSkipListSet.add(new Score("rhl",68));
        scoreSkipListSet.add(new Score("rmq",92));
        scoreSkipListSet.add(new Score("rtc",86));
        scoreSkipListSet.add(new Score("wlx",59));
        log.info("scoreSkipListSet={}", scoreSkipListSet);
    }

}

@Data
@AllArgsConstructor
class Score {
    public static ScoreComparator ScoreComparator = new ScoreComparator();
    private String name;
    private Integer score;

    static class ScoreComparator implements Comparator<Score> {
        @Override
        public int compare(Score o1, Score o2) {
            if (o1.getScore() == null) {
                return -1;
            }
            if (o2.getScore() == null) {
                return 1;
            }
            return o1.getScore().compareTo(o2.getScore());
        }
    }
}

